use std::panic;
use wasm_bindgen::prelude::*;

// Use `wee_alloc` as the global allocator.
#[global_allocator]
#[cfg(feature = "wee_alloc")]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
extern "C" {
    fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet(name: &str) {
    #[cfg(feature = "console_error_panic_hook")]
    panic::set_hook(Box::new(console_error_panic_hook::hook));

    let str = format!("hello, World {name}");
    alert(&str);

    // panic!("测试错误信息！");
}

#[wasm_bindgen]
pub fn bublle_sort(arr: &mut [i32]) {
    // arr.sort();
    let len = arr.len();
    for i in 0..len {
        for j in i + 1..len {
            if arr[i] > arr[j] {
                arr.swap(i, j)
            }
        }
    }
}
#[wasm_bindgen]
pub fn sort(arr: &mut [i32]) {
    arr.sort();
}
